package com.dianping.cat.alarm.policy.transform;

import com.dianping.cat.alarm.policy.entity.AlertPolicy;
import com.dianping.cat.alarm.policy.entity.Group;
import com.dianping.cat.alarm.policy.entity.Level;
import com.dianping.cat.alarm.policy.entity.Type;
import org.xml.sax.Attributes;







public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
/* 19 */   public AlertPolicy buildAlertPolicy(Attributes attributes) { return new AlertPolicy(); }




  
  public Group buildGroup(Attributes attributes) {
/* 26 */     String id = attributes.getValue("id");
/* 27 */     return new Group(id);
  }



  
  public Level buildLevel(Attributes attributes) {
/* 34 */     String id = attributes.getValue("id");
/* 35 */     String send = attributes.getValue("send");
/* 36 */     String suspendMinute = attributes.getValue("suspendMinute");
/* 37 */     String recoverMinute = attributes.getValue("recoverMinute");
/* 38 */     Level level = new Level(id);

/* 40 */     if (send != null) {
/* 41 */       level.setSend(send);
    }
    
/* 44 */     if (suspendMinute != null) {
/* 45 */       level.setSuspendMinute((Integer)convert(Integer.class, suspendMinute, null));
    }
    
/* 48 */     if (recoverMinute != null) {
/* 49 */       level.setRecoverMinute((Integer)convert(Integer.class, recoverMinute, null));
    }
    
/* 52 */     return level;
  }

  
  public Type buildType(Attributes attributes) {
/* 57 */     String id = attributes.getValue("id");
/* 58 */     return new Type(id);
  }



  
  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 65 */     if (value == null || value.length() == 0) {
/* 66 */       return defaultValue;
    }
    
/* 69 */     if (type == Boolean.class || type == boolean.class)
/* 70 */       return (T)Boolean.valueOf(value); 
/* 71 */     if (type == Integer.class || type == int.class)
/* 72 */       return (T)Integer.valueOf(value); 
/* 73 */     if (type == Long.class || type == long.class)
/* 74 */       return (T)Long.valueOf(value); 
/* 75 */     if (type == Short.class || type == short.class)
/* 76 */       return (T)Short.valueOf(value); 
/* 77 */     if (type == Float.class || type == float.class)
/* 78 */       return (T)Float.valueOf(value); 
/* 79 */     if (type == Double.class || type == double.class)
/* 80 */       return (T)Double.valueOf(value); 
/* 81 */     if (type == Byte.class || type == byte.class)
/* 82 */       return (T)Byte.valueOf(value); 
/* 83 */     if (type == Character.class || type == char.class) {
/* 84 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 86 */     return (T)value;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-alarm-3.0.0.jar!/com/dianping/cat/alarm/policy/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */